<?php
namespace app\modules\adminapi\controllers;

use fate\http\Request;
use app\models\Nav;
use app\libs\Util;

class AddnavController extends \app\modules\adminapi\ForceLoginPure {

    public function run() {
        $req = Request::getInstance();

        $pid = $req->getParameter('pid');
        $listorder = $req->getParameter('listorder');
        $linktype = Util::plainText($req->getParameter('linktype'));
        $title = Util::plainText($req->getParameter('title'));
        $navurl = Util::plainText($req->getParameter('navurl'));

        if(!is_numeric($pid)) {
            $pid = 0;
        }
        if(!is_numeric($listorder)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        if(!$title || !$navurl) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        $data = [
            'pid' => $pid,
            'listorder' => $listorder,
            'linktype' => $linktype,
            'title' => $title,
            'navurl' => $navurl
        ];
        // var_dump($data);exit;

        $model = new Nav();
        $ret = $model->insert($data);

        $this->ajaxReturn(null);
    }

}
